package sample.reflects.factory;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;


class init{
	public static Properties getPro() throws Exception, IOException {
		Properties pro=new Properties();
		File file=new File("./fruit.properties");
		if(file.exists()){
			pro.load(new FileInputStream(file));
			
		}else{
			pro.setProperty("apple","sample.reflects.factory.Apple" );
			pro.setProperty("orange", "sample.reflects.factory.Orange");
			pro.store(new FileOutputStream(file), "FRUIT CLASS");
		}
		return pro;
	}
}

class Factory3{
	public static fruit getInstance(String fruitName){
		fruit f=null;
		try {
			f=(fruit) Class.forName(fruitName).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return f;
	}
}

public class HelloFileProperty {

	public static void main(String[]args) throws Exception{
		Properties pro=init.getPro();

		fruit f=Factory3.getInstance(pro.getProperty("apple"));
		if(f!=null){
			f.eat();
		}
		
	}
}
